/*
ID: pallab81
PROG:
LANG: C++
*/

//"I have not failed, I have just found 10000 ways that won't work.

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define foR(i1,st,ed) for(int i1 = st,j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i,ed) foR( i , 0 , ed )
#define foE(i,st,ed) foR( i , st , ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip( X ) sleep( X )
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

template<class T1>
inline void debug(T1 _x) {
    cout<<_x<<'\n';
}
template<class T1, class T2>
inline void debug(T1 _x,T2 _y) {
    cout<<_x<<' '<<_y<<'\n';
}
template<class T1, class T2, class T3>
inline void debug(T1 _x,T2 _y,T3 _z) {
    cout<<_x<<' '<<_y<<' '<<_z<<'\n';
}
template<class T1, class T2, class T3, class T4>
inline void debug(T1 _x,T2 _y,T3 _z,T4 _zz) {
    cout<<_x<<' '<<_y<<' '<<_z<<' '<<_zz<<'\n';
}
template< class T1>
inline void debug(T1 _array,int _size) {
    cout<<"[";
    for (int i=0;i<_size;++i) {
        cout<<' '<<_array[i];
    }
    puts(" ]");
}

class TurtleSpy {
public:
	double maxDistance(vector <string> commands);
};

const double pii = (double)(2.)*acos(0);


vector<string> parse(string mystr){
    char *sentence = (char*)mystr.c_str();
    char *word;
    static char delim[]=" ";
    vector<string> words;
    for(word=strtok(sentence,delim);word; word=strtok(0,delim)){
        if( strlen(word) )
            words.pb(word);
    }
    return words;
}
inline int toI(string _str){
    // STRING EMPTY HOTE PARBE NA
    assert( LN(_str) );
    int var;
    sscanf(_str.c_str(),"%d",&var);
return var;
}

int angles[61];
int cnt;


inline pair<string,int> parseit(string str){
    vector<string> words = parse(str);
    return mk( words[0], toI(words[1]) );
}
int dp[365];
int next[365];
int prev[365];
inline void f1(){
    SET(next,0);
    next[0]=1;
    for(int i=0;i<cnt;++i){
        memcpy(prev,next,sizeof(prev));
        for(int j=0;j<360;++j){
            if(prev[j]){
                next[ (j+ angles[i])%360 ]=1;
            }
        }
    }
    memcpy(dp,next,sizeof(dp));
}
inline double fun(double f, double b, double angle){
    double var = (f*f)+(b*b)-( (double)2. * f * b * cos( (angle*pii)/180. ) );
    return sqrt(var);
}
double TurtleSpy :: maxDistance(vector <string> commands) {
    double best=-1e30;
    cnt=0;
    int f=0,b=0;
    fo(i,SZ(commands)){
        pair<string,int> cur = parseit(commands[i]);
        if(cur.first=="forward"){
            f+=cur.second;
        }
        else if(cur.first=="backward"){
            b+=cur.second;
        }
        else if(cur.first=="left"){
            angles[cnt]=cur.second;
            ++cnt;
        }
        else if(cur.first=="right"){
            angles[cnt]=(360-cur.second);
            ++cnt;
        }
    }
    f1();

    for(int i=0;i<360;++i){
        if(dp[i]){
            double var=fun( (double)f,(double)b, (double)i);
            best=max(best,var);
        }
    }
return best;
}
// BEGIN KAWIGIEDIT TESTING
// Generated by KawigiEdit 2.1.8 (beta) modified by pivanof
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool KawigiEdit_RunTest(int testNum, vector <string> p0, bool hasAnswer, double p1) {
	cout << "Test " << testNum << ": [" << "{";
	for (int i = 0; int(p0.size()) > i; ++i) {
		if (i > 0) {
			cout << ",";
		}
		cout << "\"" << p0[i] << "\"";
	}
	cout << "}";
	cout << "]" << endl;
	TurtleSpy *obj;
	double answer;
	obj = new TurtleSpy();
	clock_t startTime = clock();
	answer = obj->maxDistance(p0);
	clock_t endTime = clock();
	delete obj;
	bool res;
	res = true;
	cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
	if (hasAnswer) {
		cout << "Desired answer:" << endl;
		cout << "\t" << p1 << endl;
	}
	cout << "Your answer:" << endl;
	cout << "\t" << answer << endl;
	if (hasAnswer) {
		res = answer == answer && fabs(p1 - answer) <= 1e-9 * max(1.0, fabs(p1));
	}
	if (!res) {
		cout << "DOESN'T MATCH!!!!" << endl;
	} else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
		cout << "FAIL the timeout" << endl;
		res = false;
	} else if (hasAnswer) {
		cout << "Match :-)" << endl;
	} else {
		cout << "OK, but is it right?" << endl;
	}
	cout << "" << endl;
	return res;
}
int main() {
	bool all_right;
	all_right = true;

	vector <string> p0;
	double p1;

	{
	// ----- test 0 -----
	string t0[] = {"forward 100","backward 100","left 90"};
			p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
	p1 = 141.4213562373095;
	all_right = KawigiEdit_RunTest(0, p0, true, p1) && all_right;
	// ------------------
	}

	{
	// ----- test 1 -----
	string t0[] = {"left 45","forward 100","right 45","forward 100"};
			p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
	p1 = 200.0;
	all_right = KawigiEdit_RunTest(1, p0, true, p1) && all_right;
	// ------------------
	}

	{
	// ----- test 2 -----
	string t0[] = {"left 10","forward 40","right 30","left 10","backward 4","forward 4"};
			p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
	p1 = 40.58520737741619;
	all_right = KawigiEdit_RunTest(2, p0, true, p1) && all_right;
	// ------------------
	}

	if (all_right) {
		cout << "You're a stud (at least on the example cases)!" << endl;
	} else {
		cout << "Some of the test cases had errors." << endl;
	}
	return 0;
}
// END KAWIGIEDIT TESTING


//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
